import axios from 'axios';

// 创建 axios 实例
const $request = axios.create({
  baseURL: 'http://localhost:9999/api',
  timeout: 5000,
  headers: {
    'Content-Type': 'application/json;charset=utf-8',
  },
});

// 通过 axios 原型添加拦截器（全局生效）
$request.interceptors.request.use(
   config => {
      const token = localStorage.getItem('myToken');
	  console.log('token:' + token);
      if (token) {
        config.headers['myToken'] = token;
      }
     
      return config;
    },
  error => {
    console.log('Request Error:', error);
    return Promise.reject(error);
  }
);

export default $request;